package com.chj.jz.dp.class03;

public class Code03_HouseRobber {
	/**
	 * @param A:
	 *            An array of non-negative integers
	 * @return: The maximum amount of money you can rob tonight
	 */
	public static long houseRobber(int[] A) {
		// write your code here

		int n = A.length;
		if (n == 0) {
			return 0;
		}

		if (n == 1) {
			return A[0];
		}

		long old = 0;
		long now = A[0];
		for (int i = 2; i <= n; i++) {
			long t = Math.max(now, old + A[i - 1]);
			old = now;
			now = t;
		}

		return now;
	}

	public static void main(String[] args) {
		{
			int[] arr = new int[] { 3, 8, 4 };
			System.out.println(houseRobber(arr));
		}
		{
			int[] arr = new int[] { 5, 2, 1, 3 };
			System.out.println(houseRobber(arr));
		}
	}
}
